package com.neusoft.mapper;

import com.neusoft.po.Coupon;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CouponMapper {

	@Select("select * from coupon where userId=#{userId} order by couponId")
	public List<Coupon> listCouponByUserId(@Param("userId") String userId);

	@Select("select * from coupon where userId=#{userId} and threshold<=#{amount} order by couponId")
	public List<Coupon> listCouponByAmount(@Param("userId") String userId, @Param("amount") double amount);

	@Insert("insert into coupon(couponName, userId, threshold, discount, used) values(#{couponName}, #{userId}, #{threshold}, #{discount}, 0)")
	public Integer addCoupon(@Param("userId") String userId, @Param("couponName") String couponName, @Param("threshold") double threshold, @Param("discount") double discount);

	@Update("update coupon set used = 1 where userId=#{userId} and couponId = #{couponId}")
	public Integer useCoupon(@Param("userId") String userId, @Param("couponId") Integer couponId);

}
